package com.unitechs.trap.excel.webapi.service.impl.entity;

import com.unitechs.trap.common.pojo.trap.entity.AlarmType;
import com.unitechs.trap.common.pojo.trap.entity.AllData;
import com.unitechs.trap.excel.service.IAlarmTypeExcelService;
import com.unitechs.trap.excel.webapi.mapper.AllDataMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@DubboService
@Slf4j
@Service
public class AlarmTypeExcelServiceImpl implements IAlarmTypeExcelService {
    @Autowired
    AllDataMapper allDataMapper;

    @Override
    public List<AlarmType> listAlarmType() {
        List<AlarmType> alarmTypes=new ArrayList<>();
        List<AllData> allData = allDataMapper.listAllData();
        if (allData==null||allData.isEmpty()){return null;}
        allData.forEach(data->{
            if (data.getAllIndex()==1) {
                AlarmType alarmType = new AlarmType();
                BeanUtils.copyProperties(data, alarmType);
                alarmType.setTid(UUID.randomUUID().toString());
                LocalDateTime localDateTime = LocalDateTime.now();
                alarmType.setCreateTime(localDateTime);
                alarmType.setModifyTime(localDateTime);
                alarmType.setSpecialty("ALL");
                alarmTypes.add(alarmType);
            }
        });
        return alarmTypes;
    }
}
